package com.hrma.services.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hrma.dao.TravelApplicationMapper;
import com.hrma.dao.TravelRecordMapper;
import com.hrma.entity.SelectResult;
import com.hrma.entity.TravelRecord;
import com.hrma.entity.TravelRecordDTO;
import com.hrma.entity.TravelRecordVO;
import com.hrma.services.TravelRecordService;
import com.hrma.utils.UserUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelRecordImpl implements TravelRecordService {
    private final TravelRecordMapper travelRecordMapper;

    public TravelRecordImpl(TravelRecordMapper travelRecordMapper, TravelApplicationMapper travelApplicationMapper) {
        this.travelRecordMapper = travelRecordMapper;
        this.travelApplicationMapper = travelApplicationMapper;
    }

    private final TravelApplicationMapper travelApplicationMapper;

    @Override
    public TravelRecordVO add(TravelRecordVO data) {
        data.setAuditorId(UserUtil.getUserId());
        travelRecordMapper.add(data);
        travelApplicationMapper.setState(data.getState(),data.getApplicationId());
        return data;
    }

    @Override
    public List<SelectResult> select() {
        return travelRecordMapper.select();
    }

    @Override
    public Page<TravelRecordVO> getList(TravelRecordDTO data) {
        PageHelper.startPage(data.getPageNum(), data.getPageSize());
        return travelRecordMapper.getList(data);
    }

    @Override
    public Page<TravelRecordVO> getPersonalList(TravelRecordDTO data) {
        data.setEmployeeId(UserUtil.getUserId());
        PageHelper.startPage(data.getPageNum(), data.getPageSize());
        return travelRecordMapper.getList(data);
    }
}
